﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPLDB.DA.Interfaces.UI;
using System.ComponentModel.Composition;
using WPLDB.Infrastucture.UI.ViewModelBase;
using Microsoft.Practices.Prism.Events;
using WPLDB.Infrastucture.UI.Events;

namespace WPLDB.Package.UI.ViewModel
{
    /// <summary>
    /// This View Model helps to displace the header name and image
    /// </summary>
    [Export(typeof(IHeaderViewModel))]
    public class HeaderViewModel : ViewModelBase, IHeaderViewModel
    {
        #region "ctor"
        [ImportingConstructor]
        public HeaderViewModel(IHeaderView view, IEventAggregator eventAggregator)
        {
            this.View = view;
            this.View.SetViewModel(this);
            eventAggregator.GetEvent<ChooseViewChangedEvent<object>>().Subscribe(param => this.CatchEvent(param));

        }

        #endregion

        #region "Interface Implementation"
        public DA.Interfaces.UI.Base.IBaseView View
        {
            get;
            set;
        } 
        #endregion

        #region "Properties"
        private string _headerName;

        public string HeaderName
        {
            get { return _headerName; }
            set
            {
                if (value != _headerName)
                {
                    _headerName = value;
                    base.OnPropertyChanged(() => HeaderName);

                }
            }
        }

        public string HeaderImage
        {
            get
            {
                return "images/Header.jpg";
            }
        } 
        #endregion

        #region "Methods"

        private void CatchEvent(object param)
        {
            if (null != param && param.GetType() == typeof(string))
            {
                HeaderName = param.ToString();
            }
        } 
        #endregion
    }
}
